<template>
	<view>
		<view class="nav-chuli">
			<view class="uni-flex" v-if="deptKey!='chuli'&&deptKey!='shuiwu'">
				<view>反映类别：</view>
				<view class="uni-set">
					<view class="uni-picker">
						<picker @change="bindPickerChange2" :value="index2" :range="array2" range-key="dictName">
							<view>{{ reflectCategoryName }}</view>
						</picker>
					</view>
					<image src="/static/img/fanhui-right.png" mode=""></image>
				</view>
			</view>
			
			<view class="uni-flex" v-if="deptKey!='chuli'&&deptKey!='shuiwu'">
				<view>处理意见：</view>
				<input type="text" v-model="handleOpinion" placeholder="请输入" />
			</view>
			
			<view class="uni-flex" v-if="deptKey!='chuli'&&deptKey!='shuiwu'">
				<view>驳回原因：</view>
				<input type="text" v-model="officeRejectReason" placeholder="请输入" />
			</view>
			
			<view class="uni-flex" v-if="deptKey=='shuiwu'">
				<view>处理意见：</view>
				<input type="text" v-model="waterOpinion" placeholder="请输入" />
			</view>

			<view class="uni-flex" v-if="deptKey=='shuiwu'">
				<view>驳回原因：</view>
				<input type="text" v-model="waterRejectReason" placeholder="请输入" />
			</view>
			
		</view>

		<view class="submit" @click="submit()">确认</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list:[],
			orderID: '',
			deptKey: '',
			waterOpinion: '', //水务处理意见
			waterRejectReason: '', //水务驳回原因
			
			array2: [],
			index2: 0,
			reflectCategoryName: '选择', //办公室退回反映类别
			reflectCategory: '', //办公室退回反映类别id
			
			handleOpinion: '', //办公室处理意见
			officeRejectReason: '' ,//办公室驳回原因
		};
	},
	onLoad(e) {
		this.orderID = e.orderID;
		this.deptKey = e.deptKey;
		this.list = JSON.parse(e.list)
		// 水务
		this.waterOpinion = this.list.waterOpinion
		this.waterRejectReason = this.list.waterRejectReason
		// 办公室
		this.handleOpinion = this.list.handleOpinion
		this.officeRejectReason = this.list.officeRejectReason
		this.reflectCategory = this.list.reflectCategory
		if(!this.reflectCategory){
			this.reflectCategoryName = '选择'
		}else{
			this.reflectCategoryName = this.list.reflectCategoryName
		}
		if (this.deptKey == 'liqun' || this.deptKey == 'kuncheng' || this.deptKey == 'wushui' || this.deptKey == 'zilaishui') {
			this.leibie();
		}
	},
	methods: {
		// 办公室的反应类别
		leibie() {
			var that = this;
			uni.request({
				url: '/app/wechatApi/wechatOneFiveOrder/getDictsRelectWe',
				method: 'get',
				data: {
					code: 'oneFiveOrderReflectCate',
					openid: uni.getStorageSync('openid')
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						that.array2 = res.data.data;
						// console.log(res.data.data)
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},
		// 办公室选择反应类别
		bindPickerChange2: function(e) {
			// console.log('picker发送选择改变，携带值为', e.target.value);
			this.index2 = e.target.value;
			this.reflectCategoryName = this.array2[e.target.value].dictName;
			this.reflectCategory = this.array2[e.target.value].dictCode;
			console.log(this.reflectCategoryName, this.reflectCategory, '==办公室选择反应类别');
		},

		// 驳回
		submit() {
			var that = this;
			var values;
			if (this.deptKey == 'shuiwu') {
				if(!that.waterRejectReason){
					uni.showToast({
						title:'请输入驳回原因',
						icon:'none',
						duration:1500
					})
					return
				}
				values = {
					orderId: this.orderID,
					openid: uni.getStorageSync('openid'),
					handlePoint: 'return',
					waterRejectReason: that.waterRejectReason ,
					waterOpinion: that.waterOpinion,
				};
			} else if (this.deptKey == 'liqun' || this.deptKey == 'kuncheng' || this.deptKey == 'wushui' || this.deptKey == 'zilaishui') {
				if(!that.officeRejectReason){
					uni.showToast({
						title:'请输入驳回原因',
						icon:'none',
						duration:1500
					})
					return
				}
				values = {
					orderId: this.orderID,
					openid: uni.getStorageSync('openid'),
					handlePoint: 'return',
					reflectCategory: that.reflectCategory,
					handleOpinion: that.handleOpinion,
					officeRejectReason: that.officeRejectReason,
				};
			}
			uni.showLoading({
				mask: false
			});
			uni.request({
				url: '/app/wechatApi/wechatOneFiveOrder/handleOrder',
				method: 'POST',
				data: values,
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					uni.hideLoading();
					if (res.data.code === 200) {
						uni.showToast({
							title: '操作成功!',
							icon: 'none'
						});
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							});
						}, 1500);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		}
	}
};
</script>

<style lang="less">
.nav-chuli {
	padding:1upx;

	.uni-flex {
		box-shadow: 0px 0px 4px 4px rgba(0, 1, 2, 0.08);
		margin: 25upx;
		padding: 25upx;
		border-radius: 15upx;
		white-space: nowrap;
		
		input {
			width: 70%;
			color: #666;
			font-size: 30upx;
		}
		image {
			width: 230upx;
			height: 230upx;
			margin-top: 25upx;
		}

		.uni-set {
			width: 70%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.uni-picker {
				width: 90%;
				padding-left: 15upx;
			}
			image {
				width: 20upx;
				height: 25upx;
				margin-top: -3upx;
			}
		}
	}
}
// 提交
.submit {
	background: #48E6E7;
	color: #ffffff;
	text-align: center;
	padding: 10upx 0;
	margin: 25upx;
	margin-top: 150upx;
	border-radius: 25upx;
}
</style>
